
package cn.edu.scau.cmi.hombio.service;

import cn.edu.scau.cmi.hombio.domain.Pig;
import cn.edu.scau.cmi.hombio.domain.Sale;
import cn.edu.scau.cmi.hombio.domain.SalePig;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/pigRs-security-context.xml",
		"file:./resources/pigRs-service-context.xml",
		"file:./resources/pigRs-dao-context.xml",
		"file:./resources/pigRs-web-context.xml" })
@Transactional
public class SalePigServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected SalePigService service;

	/**
	 * Instantiates a new SalePigServiceTest.
	 *
	 */
	public SalePigServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	* Return a count of all SalePig entity
	* 
	 */
	@Test
	public void countSalePigs() {
		Integer response = null;
		response = service.countSalePigs();
		// TODO: JUnit - Add assertions to test outputs of operation: countSalePigs
	}

	/**
	 * Operation Unit Test
	* Save an existing Pig entity
	* 
	 */
	@Test
	public void saveSalePigPig() {
		// TODO: JUnit - Populate test inputs for operation: saveSalePigPig 
		Integer id = 0;
		Pig related_pig = new cn.edu.scau.cmi.hombio.domain.Pig();
		SalePig response = null;
		response = service.saveSalePigPig(id, related_pig);
		// TODO: JUnit - Add assertions to test outputs of operation: saveSalePigPig
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findSalePigByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findSalePigByPrimaryKey 
		Integer id_1 = 0;
		SalePig response = null;
		response = service.findSalePigByPrimaryKey(id_1);
		// TODO: JUnit - Add assertions to test outputs of operation: findSalePigByPrimaryKey
	}

	/**
	 * Operation Unit Test
	* Delete an existing Sale entity
	* 
	 */
	@Test
	public void deleteSalePigSale() {
		// TODO: JUnit - Populate test inputs for operation: deleteSalePigSale 
		Integer salepig_id = 0;
		Integer related_sale_id = 0;
		SalePig response = null;
		response = service.deleteSalePigSale(salepig_id, related_sale_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteSalePigSale
	}

	/**
	 * Operation Unit Test
	* Delete an existing SalePig entity
	* 
	 */
	@Test
	public void deleteSalePig() {
		// TODO: JUnit - Populate test inputs for operation: deleteSalePig 
		SalePig salepig = new cn.edu.scau.cmi.hombio.domain.SalePig();
		service.deleteSalePig(salepig);
	}

	/**
	 * Operation Unit Test
	* Delete an existing Pig entity
	* 
	 */
	@Test
	public void deleteSalePigPig() {
		// TODO: JUnit - Populate test inputs for operation: deleteSalePigPig 
		Integer salepig_id_1 = 0;
		Integer related_pig_id = 0;
		SalePig response = null;
		response = service.deleteSalePigPig(salepig_id_1, related_pig_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteSalePigPig
	}

	/**
	 * Operation Unit Test
	* Return all SalePig entity
	* 
	 */
	@Test
	public void findAllSalePigs() {
		// TODO: JUnit - Populate test inputs for operation: findAllSalePigs 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<SalePig> response = null;
		response = service.findAllSalePigs(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllSalePigs
	}

	/**
	 * Operation Unit Test
	* Save an existing SalePig entity
	* 
	 */
	@Test
	public void saveSalePig() {
		// TODO: JUnit - Populate test inputs for operation: saveSalePig 
		SalePig salepig_1 = new cn.edu.scau.cmi.hombio.domain.SalePig();
		service.saveSalePig(salepig_1);
	}

	/**
	 * Operation Unit Test
	* Load an existing SalePig entity
	* 
	 */
	@Test
	public void loadSalePigs() {
		Set<SalePig> response = null;
		response = service.loadSalePigs();
		// TODO: JUnit - Add assertions to test outputs of operation: loadSalePigs
	}

	/**
	 * Operation Unit Test
	* Save an existing Sale entity
	* 
	 */
	@Test
	public void saveSalePigSale() {
		// TODO: JUnit - Populate test inputs for operation: saveSalePigSale 
		Integer id_2 = 0;
		Sale related_sale = new cn.edu.scau.cmi.hombio.domain.Sale();
		SalePig response = null;
		response = service.saveSalePigSale(id_2, related_sale);
		// TODO: JUnit - Add assertions to test outputs of operation: saveSalePigSale
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
